require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')

require('../lib/iconfont/iconfont.css')

// axios
const axios=require('axios')

// 底部导航
const util=require('../lib/util/util')
util.commonFoot('mine')

// weui-轻提示
require('weui')
const weui= require('weui.js')

require('../css/mine.less')

window.addEventListener('DOMContentLoaded',function(){
    let userId=localStorage.getItem('userId')
    let imgurl=document.querySelector('#imgurl')
    let nickname=document.querySelector('#nickname')
    let sign=document.querySelector('#sign')
    
    let sports=document.querySelector('#sports')
    let badge=document.querySelector('#badge')

    // 个人动态
    let dynamicCount=document.querySelector('#dynamicCount')

    // 运动数据
    let coursetims=document.querySelector('#coursetims')
    let calorie=document.querySelector('#calorie')

    // 徽章
    let myBadge=document.querySelectorAll('#myBadge img')

    let loginBtn=document.querySelector('#loginBtn')

    let userIcon=document.querySelector('#user-icon')

    axios.get('http://139.9.177.51:8099/users/mysportsBadge?userId='+userId)
    .then(function(res){
        user=res.data.data.user
        console.log(res.data);
        if(user.imgurl){
            imgurl.src=user.imgurl
        }
        if(user.sign){
            sign.textContent=user.sign
        }
            nickname.textContent=user.nickname

            // 个人动态
            dynamicCount.textContent=res.data.data.dynamicCount

            // 运动数据
            coursetims.textContent=res.data.data.sports.coursetims
            calorie.textContent=res.data.data.sports.calorie

            // img徽章
            let myBadgeArr=res.data.data.myBadge
            myBadgeArr.forEach(function(v,i){
                myBadge[i].src=v
            })
    })

    loginBtn.addEventListener('click',function(){
        weui.confirm('确定要退出吗，此操作不可逆哦~',function(){
            // 清除存储内容
            localStorage.clear()
            // 跳转到登录页面
            location.href="./login.html"
        })
    })

    userIcon.addEventListener('click',function(){
        location.href="./modify.html"
    })

    sports.addEventListener('click',function(){
        location.href='./motion.html'
    })

    badge.addEventListener('click',function(){
        location.href='./badge.html'
    })
})


